home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / csim / source.lha / source / Threads / GnuThreads / timer.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-14  |  1.4 KB  |  62 lines

  1. /*
  2.  * timer.c -- an example program to demonstrate lightweight
  3.  * processes and time.
  4.  * Copyright (C) 1991 Stephen Crane.
  5.  *
  6.  * This is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 1, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This software is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * author: Stephen Crane, (jsc@doc.ic.ac.uk), Department of Computing,
  21.  * Imperial College of Science, Technology and Medicine, 180 Queen's
  22.  * Gate, London SW7 2BZ, England.
  23.  */
  24.  
  25. #include <sysent.h>
  26. #include <stdio.h>
  27. #include "gnulwp.h"
  28.  
  29. struct sem *ends;
  30.  
  31. void f (Thread_Par)
  32. {
  33.     int i; char ch='O';
  34.     for (i=1; i<1000; i++) {
  35.         delayp (25*i);
  36.         write (1, &ch, 1);
  37.     }
  38.     signals (ends);
  39.     suicidep ();
  40. }
  41.  
  42. void g (Thread_Par)
  43. {
  44.     int i; char ch=' ';
  45.     for (i=1; i<1000; i++) {
  46.         delayp (35*i);
  47.         write (1, &ch, 1);
  48.     }
  49.     signals (ends);
  50.     suicidep ();
  51. }
  52.  
  53. main ()
  54. {
  55.     initlp (1);
  56.     ends = creats (0);
  57.     creatp (2, g, 8192, 0, 0, 0);
  58.     creatp (2, f, 8192, 0, 0, 0);
  59.     waits (ends);
  60.     waits (ends);
  61. }
  62.